package com.ctrip.corp.obt.shard.configuration;

import com.ctrip.corp.obt.generic.utils.Conditional;

/**
 * Configuration settings for the Security Fuzzy Query.
 */
public interface SecurityFuzzyQueryConfig {

    /**
     * Get the value associated with a key.
     *
     * @param k Key to lookup in the config.
     * @return Value for the key or null if no key is present.
     */
    String get(String k);


    /**
     * 是否启用模糊查询的select处理功能
     * @return
     */
    default Boolean enabledQuery() {
        String v = get("fuzzy.enabled.query");
        return Conditional.ofNullable(v).map(Boolean::valueOf).orElse(true);
    }

    /**
     * 是否启用模糊查询的update及insert处理功能
     * @return
     */
    default Boolean enabledCommand() {
        String v = get("fuzzy.enabled.command");
        return Conditional.ofNullable(v).map(Boolean::valueOf).orElse(true);
    }

    /**
     * 是否启用对模糊查询的like匹配的降级功能:
     * 将加密字段的like匹配降级为原加密字段的精准匹配
     * @return
     */
    default Boolean enabledDegradation() {
        String v = get("fuzzy.enabled.degradation");
        return Conditional.ofNullable(v).map(Boolean::valueOf).orElse(false);
    }


}
